#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define ptr(a, n) \
for (int i = 0; i < n; i++) \
{ \
cout << a[i] << ' '; \
}
#define fort(z, x, t) for (ll z = x; z < t; z++)
#define rev(z, x, t) for (ll z = t; z > x; z--)
#define arin(a, n) \
ll a[n]; \
for (ll i = 0; i < n; i++) \
{ \
cin >> a[i]; \
}
#define pb push_back
#define vein(v, n) \
vector<ll> v; \
for (ll i = 0; i < n; i++) \
{ \
ll x; \
cin >> x; \
v.pb(x); \
}
#define seint(s, n) \
set<int> s; \
for (ll i = 0; i < n; i++) \
{ \
ll x; \
cin >> x; \
s.insert(x); \
}
#define vint(v) vector<ll> v;
#define vstring(vs, n) \
vector<string> vs; \
for (ll i = 0; i < n; i++) \
{ \
string s; \
cin >> s; \
vs.pb(s); \
}
#define num(n) \
ll n; \
cin >> n;
#define out(n) cout << n << endl;
#define sortv(v) sort(v.begin(), v.end());
#define mpll map<ll, ll> mpi;
#define mpchar map<char, ll> mpc;
#define cin(a, n, b) \
f(i, n) \
{ \
cin >> a[i]; \
b[i] = a[i]; \
}
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 1e5 + 10;
int mod = 1e9 + 7;
void solve()
{
int n,m;
cin>>n>>m;
int grid[n+1][m+1];
int count=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
grid[i][j]=count;
count++;
}
}
int k=1;
int f1=1;
int l=((n+1)/2)+1;
int f2=0;
if(n==4){
l=3;
k=1;
f2=1;
f1=0;
}
while(n--){
if(f1){
for(int i=1;i<=m;i++){
cout<<grid[k][i]<<" ";
}
cout<<endl;
k++;
f1=0;
f2=1;
}
else{
for(int i=1;i<=m;i++){
cout<<grid[l][i]<<" ";
}
cout<<endl;
l++;
f2=0;
f1=1;
}
}
cout<<endl;
}
signed main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin >> t;
fort(i, 0, t)
solve();
return 0;
}
1399A - Remove Smallest | 208A - Dubstep |
1581A - CQXYM Count Permutations | 337A - Puzzles |
495A - Digital Counter | 796A - Buying A House |
67A - Partial Teacher | 116A - Tram |
1472B - Fair Division | 1281C - Cut and Paste |
141A - Amusing Joke | 112A - Petya and Strings |
677A - Vanya and Fence | 1621A - Stable Arrangement of Rooks |
472A - Design Tutorial Learn from Math | 1368A - C+= |
450A - Jzzhu and Children | 546A - Soldier and Bananas |
32B - Borze | 1651B - Prove Him Wrong |
381A - Sereja and Dima | 41A - Translation |
1559A - Mocha and Math | 832A - Sasha and Sticks |
292B - Network Topology | 1339A - Filling Diamonds |
910A - The Way to Home | 617A - Elephant |
48A - Rock-paper-scissors | 294A - Shaass and Oskols |